<?php
declare (strict_types = 1);

namespace app\controller;

use app\helpers\api\ApiResponse;
use app\model\Template;
use think\Request;

class TemplateController
{
    use ApiResponse;
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        return $this->success(Template::field('id,name,type,content')->select());
    }

    public function show(Template $template)
    {
        return $this->success($template);
    }

    public function homeShow(Template $template)
    {
        return $this->success($template);
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        Template::create($request->param());
        return $this->created();
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request, Template $template)
    {
        $template->update($request->param());
        return  $this->update();
    }

    /**
     * 删除
     * @param Template $template
     * @return mixed
     */
    public function delete(Template $template)
    {
        $template->delete();
        return $this->destroy();
    }
}
